package com.yzjs.config;

import java.util.Objects;

public class PayConfig {

    private String notifyUrl;
    private String returnUrl;

    PayConfig() {
    }

    public String getNotifyUrl() {
        return this.notifyUrl;
    }

    public void setNotifyUrl(String notifyUrl) {
        this.notifyUrl = notifyUrl;
    }

    public String getReturnUrl() {
        return this.returnUrl;
    }

    public void setReturnUrl(String returnUrl) {
        this.returnUrl = returnUrl;
    }

    public void check() {
        Objects.requireNonNull(this.notifyUrl, "config param 'notifyUrl' is null.");
        if (!this.notifyUrl.startsWith("http") && !this.notifyUrl.startsWith("https")) {
            throw new IllegalArgumentException("config param 'notifyUrl' does not start with http/https.");
        } else if (this.notifyUrl.length() > 256) {
            throw new IllegalArgumentException("config param 'notifyUrl' is incorrect: size exceeds 256.");
        } else {
            if (this.returnUrl != null) {
                if (!this.returnUrl.startsWith("http") && !this.returnUrl.startsWith("https")) {
                    throw new IllegalArgumentException("config param 'returnUrl' does not start with http/https.");
                }

                if (this.returnUrl.length() > 256) {
                    throw new IllegalArgumentException("config param 'returnUrl' is incorrect: size exceeds 256.");
                }
            }

        }
    }
}
